#include "dialog.h"
#include "ui_dialog.h"
#include <QPushButton>
#include <iostream>
#include <QCheckBox>
#include <QRadioButton>
#include <QPalette>


using namespace std;

Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dialog),qf("宋体",14)
{
    ui->setupUi(this);

    underLine = ui->checkBox;
    italic = ui->checkBox_2;
    bold = ui->checkBox_3;

    blue = ui->radioButton_3;
    red = ui->radioButton_2;
    black = ui->radioButton_4;

    pte = ui->plainTextEdit;
    ui->plainTextEdit->setPlainText("hello world!");

    QPushButton * btn = ui->pushButton;
    QPushButton * btn2 = ui->pushButton_2;

    connect(underLine,&QCheckBox::stateChanged,this,&Dialog::setPteFont);
    connect(italic,&QCheckBox::stateChanged,this,&Dialog::setPteFont);
    connect(bold,&QCheckBox::stateChanged,this,&Dialog::setPteFont);

    connect(blue,&QRadioButton::clicked,this,&Dialog::setPteColor);
    connect(red,&QRadioButton::clicked,this,&Dialog::setPteColor);
    connect(black,&QRadioButton::clicked,this,&Dialog::setPteColor);

    connect(btn,&QPushButton::clicked,this,&Dialog::close);
    connect(btn2,&QPushButton::clicked,this,&Dialog::close);

}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::setPteFont()
{
    this->qf.setUnderline(this->underLine->checkState());
    this->qf.setItalic(this->italic->checkState());
    this->qf.setBold(this->bold->checkState());
    this->qf.setPointSize(20);
    this->pte->setFont(this->qf);
}

void Dialog::setPteColor()
{
    QPalette palette= pte->palette();
    if( blue->isChecked())
    {
        palette.setColor(QPalette::Base, Qt::blue);
        cout << "blue" << endl;
    }
    else if(red->isChecked())
    {
        palette.setColor(QPalette::Base, Qt::red);
        cout << "red" << endl;
    }
    else if(black->isChecked())
    {
        palette.setColor(QPalette::Base,Qt::black);
        cout << "black" << endl;
    }
    pte->setPalette(palette);
}


